return NULL;
}
-static ClutterActor *
-window_backed_app_get_icon (ShellApp *app,
- int size)
+static GIcon *
+window_backed_app_get_icon (ShellApp *app)
{
MetaWindow *window = NULL;
- StWidget *widget;
- int scale, scaled_size;
- ShellGlobal *global;
- StThemeContext *context;
-
- global = shell_global_get ();
- context = st_theme_context_get_for_stage (shell_global_get_stage (global));
- g_object_get (context, "scale-factor", &scale, NULL);
-
- scaled_size = size * scale;
/* During a state transition from running to not-running for
* window-backend apps, it's possible we get a request for the icon.
- * Avoid asserting here and just return an empty image.
+ * Avoid asserting here and just return a fallback icon
*/
if (app->running_state != NULL)
window = window_backed_app_get_window (app);
- if (window == NULL)
- {
- ClutterActor *actor;
-
- actor = clutter_actor_new ();
- g_object_set (actor,
- "opacity", 0,
- "width", (float) scaled_size,
- "height", (float) scaled_size,
- NULL);
- return actor;
- }
-
- if (meta_window_get_client_type (window) == META_WINDOW_CLIENT_TYPE_X11)
- {
- StWidget *texture_actor;
-
- texture_actor =
- st_texture_cache_bind_cairo_surface_property (st_texture_cache_get_default (),
- G_OBJECT (window),
- "icon",
- scaled_size);
-
- widget = g_object_new (ST_TYPE_BIN,
- "child", texture_actor,
- NULL);
- }
- else
- {
- widget = g_object_new (ST_TYPE_ICON,
- "icon-size", size,
- "icon-name", "application-x-executable",
- NULL);
- }
- st_widget_add_style_class_name (widget, "fallback-app-icon");
-
- return CLUTTER_ACTOR (widget);
+ if (window &&
+ meta_window_get_client_type (window) == META_WINDOW_CLIENT_TYPE_X11)
+ return st_texture_cache_bind_cairo_surface_property (st_texture_cache_get_default (),
+ G_OBJECT (window),
+ "icon");
+ return g_themed_icon_new ("application-x-executable");
}
/**
shell_app_create_icon_texture (ShellApp *app,
int size)
{
- GIcon *icon;
+ g_autoptr (GIcon) icon = NULL;
ClutterActor *ret;
- if (app->info == NULL)
- return window_backed_app_get_icon (app, size);
-
ret = st_icon_new ();
st_icon_set_icon_size (ST_ICON (ret), size);
st_icon_set_fallback_icon_name (ST_ICON (ret), "application-x-executable");
- icon = g_app_info_get_icon (G_APP_INFO (app->info));
+ if (app->info == NULL)
+ {
+ icon = window_backed_app_get_icon (app);
+ st_widget_add_style_class_name (ST_WIDGET (ret), "fallback-app-icon");
+ }
+ else
+ {
+ icon = g_app_info_get_icon (G_APP_INFO (app->info));
+ g_object_ref (icon);
+ }
+
st_icon_set_gicon (ST_ICON (ret), icon);
return ret;
typedef struct {
StTextureCache *cache;
- ClutterActor *actor;
- gint size;
+ ClutterContent *image;
GObject *source;
gulong notify_signal_id;
gboolean weakref_active;
(cairo_image_surface_get_format (surface) == CAIRO_FORMAT_ARGB32 ||
cairo_image_surface_get_format (surface) == CAIRO_FORMAT_RGB24))
{
- g_autoptr(ClutterContent) image = NULL;
g_autoptr(GError) error = NULL;
- int size = bind->size;
+ int width, height, size;
- if (size < 0)
- clutter_actor_get_preferred_width (bind->actor, -1, NULL, (float *)&size);
+ width = cairo_image_surface_get_width (surface);
+ height = cairo_image_surface_get_width (surface);
+ size = MAX(width, height);
- image = clutter_actor_get_content (bind->actor);
- if (!image || !CLUTTER_IS_IMAGE (image))
- image = st_image_content_new_with_preferred_size (size, size);
- else
- g_object_ref (image);
+ if (!bind->image)
+ bind->image = st_image_content_new_with_preferred_size (size, size);
- clutter_image_set_data (CLUTTER_IMAGE (image),
+ clutter_image_set_data (CLUTTER_IMAGE (bind->image),
cairo_image_surface_get_data (surface),
cairo_image_surface_get_format (surface) == CAIRO_FORMAT_ARGB32 ?
COGL_PIXEL_FORMAT_BGRA_8888 : COGL_PIXEL_FORMAT_BGR_888,
- cairo_image_surface_get_width (surface),
- cairo_image_surface_get_height (surface),
+ width,
+ height,
cairo_image_surface_get_stride (surface),
&error);
- if (image)
- clutter_actor_set_content (bind->actor, image);
- else if (error)
+ if (error)
g_warning ("Failed to allocate texture: %s", error->message);
-
- clutter_actor_set_opacity (bind->actor, 255);
}
else
- clutter_actor_set_opacity (bind->actor, 0);
+ bind->image = g_object_new (ST_TYPE_IMAGE_CONTENT,
+ "preferred-width", 0, /* tough luck */
+ "preferred-height", 0,
+ NULL);
}
static void
{
StTextureCachePropertyBind *bind = data;
if (bind->weakref_active)
- g_object_weak_unref (G_OBJECT (bind->actor), st_texture_cache_bind_weak_notify, bind);
+ g_object_weak_unref (G_OBJECT (bind->image), st_texture_cache_bind_weak_notify, bind);
g_slice_free (StTextureCachePropertyBind, bind);
}
/**
* st_texture_cache_bind_cairo_surface_property:
* @cache:
- * @object: A #GObject with a property @property_name of type #GdkPixbuf
+ * @object: A #GObject with a property @property_name of type #cairo_surface_t
* @property_name: Name of a property
*
- * Create a #ClutterActor which tracks the #cairo_surface_t value of a GObject property
+ * Create a #GIcon which tracks the #cairo_surface_t value of a GObject property
* named by @property_name. Unlike other methods in StTextureCache, the underlying
* #CoglTexture is not shared by default with other invocations to this method.
*
* If the source object is destroyed, the texture will continue to show the last
* value of the property.
*
- * Return value: (transfer none): A new #StWidget
+ * Return value: (transfer none): A new #GIcon
*/
-StWidget *
+GIcon *
st_texture_cache_bind_cairo_surface_property (StTextureCache *cache,
GObject *object,
- const char *property_name,
- gint size)
+ const char *property_name)
{
- StWidget *widget;
gchar *notify_key;
StTextureCachePropertyBind *bind;
- widget = g_object_new (ST_TYPE_WIDGET,
- "opacity", 0,
- "width", (float)size,
- "height", (float)size,
- NULL);
-
bind = g_slice_new0 (StTextureCachePropertyBind);
bind->cache = cache;
- bind->actor = CLUTTER_ACTOR (widget);
- bind->size = size;
bind->source = object;
- g_object_weak_ref (G_OBJECT (widget), st_texture_cache_bind_weak_notify, bind);
- bind->weakref_active = TRUE;
st_texture_cache_reset_texture (bind, property_name);
+ g_object_weak_ref (G_OBJECT (bind->image), st_texture_cache_bind_weak_notify, bind);
+ bind->weakref_active = TRUE;
+
notify_key = g_strdup_printf ("notify::%s", property_name);
bind->notify_signal_id = g_signal_connect_data (object, notify_key, G_CALLBACK(st_texture_cache_on_pixbuf_notify),
bind, (GClosureNotify)st_texture_cache_free_bind, 0);
g_free (notify_key);
- return widget;
+ return G_ICON (bind->image);
}
/**